let oldArrayProtoMethods = Array.prototype
// 不能直接改写数组原有方法，不可靠

export let arrayMethods =Object.create(Array.prototype)

//会改变原数组的7种方法
let methods = [
    'push',
    'pop',
    'shift',
    'unshift',
    'splice',
    'reverse',
    'sort'
]

methods.forEach(method => {
   
    arrayMethods[method] = function(...args){
        let inserted;
        let ob = this.__ob__
        console.log('数组变化了')
        switch (method){
            case 'push':
            case 'unshift':
                inserted = args
                break
            case 'splice':
                inserted = args.slice(2)
                break
            
        }
        if(inserted) ob.observeArray(inserted)
      let result = oldArrayProtoMethods[method].call(this,...args)
      return result
    }
})